package com.project.common.pagination;

import com.project.common.pagination.handler.MySQLPaginationHandler;

import java.util.HashMap;
import java.util.Map;

public final class PaginationHandlerFactory {
    private static final Map<String, PaginationHandler> PAGINATION_HANDLER = new HashMap<>();

    private PaginationHandlerFactory() {
        PAGINATION_HANDLER.put("MYSQL", new MySQLPaginationHandler());
    }

    public static PaginationHandlerFactory getDefault() {
        return Singleton.Instance.getPaginationHandlerFactory();
    }

    public PaginationHandler getPaginationHandler(String dialect) {
        if (dialect == null) {
            return null;
        }
        return PAGINATION_HANDLER.get(dialect.toUpperCase());
    }

    private enum Singleton {
        Instance;

        private PaginationHandlerFactory paginationHandlerFactory;

        Singleton() {
            this.paginationHandlerFactory = new PaginationHandlerFactory();
        }

        public PaginationHandlerFactory getPaginationHandlerFactory() {
            return paginationHandlerFactory;
        }
    }
}
